package neusoft.edu.cn.a215lmeordering.model;

import neusoft.edu.cn.a215lmeordering.Listener.Listener;
import neusoft.edu.cn.a215lmeordering.bean.Register;
import neusoft.edu.cn.a215lmeordering.service.AllService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RegisterModel {

    private Retrofit retrofit;

    public RegisterModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175:8080/foodService/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void getResultList(String username,String password,String mobilenum,
                              String address,String comment,final Listener registerListener){

        AllService registerService = retrofit.create(AllService.class);

        Call<Register> registerCall = registerService.getRegister(username,password,mobilenum,address,comment);

        registerCall.enqueue(new Callback<Register>() {
                @Override
                public void onResponse(Call<Register> call, Response<Register> response) {
                    if(response!=null)
                        registerListener.onResponse(response.body());
                    else registerListener.onFail("获取登录信息失败");
                }

            @Override
            public void onFailure(Call<Register> call, Throwable t) {
                registerListener.onFail(t.toString());
            }
        });
    }
}
